#include "cv_match/base.hpp"

using namespace cv;
using namespace std;

string win_name = "test";
string img_path = "D:/dev/codes/cv_match/data/scenary3.jpg";

void read_img()
{
	cv::Mat img = cv::imread(img_path);

	// 检查图像是否加载成功
	if (img.empty()) {
		std::cout << "图像加载失败" << std::endl;
	}

	int width = img.cols;  //图像的宽对应着列数
	int height = img.rows; //图像的高对应着行数
	cout << "image width " << width << endl;
	cout << "image height " << height << endl;

	cv::Mat gray;
	// 使用cv::cvtColor函数将彩色图像转换为灰度图像  
	cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY);

	// 设置想要获取像素值的坐标 (x, y)
	int x = 10;
	int y = 20;

	// 获取单通道图像像素值
	uchar pixelValue = gray.at<uchar>(y, x);
	std::cout << "pixel value at (" << x << ", " << y << "): " << (int)pixelValue << std::endl;

	// 获取多通道图像像素值（如BGR）
	cv::Vec3b pixelBGR = img.at<cv::Vec3b>(y, x);
	std::cout << "pixel BGR value at (" << x << ", " << y << "): ("
		<< (int)pixelBGR[0] << ", "
		<< (int)pixelBGR[1] << ", "
		<< (int)pixelBGR[2] << ")" << std::endl;


	cv::Mat grayResize;
	// 新的宽度和高度
	cv::Size newSize(gray.cols / 4, gray.rows / 4);
	// 调整图像大小
	cv::resize(gray, grayResize, newSize);

	// 显示灰度图像  
	cv::namedWindow(win_name, cv::WINDOW_AUTOSIZE);
	cv::imshow(win_name, grayResize);
	// 等待任意键盘按键按下  
	cv::waitKey(0);
}

int main()
{
	read_img();
	return 0;
}